﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FileDuplicateRemover.Core
{
    public class DuplicateEntityDescriptionList : IEnumerable<DuplicateEntityDescription>
    {
        private readonly List<DuplicateEntityDescription> _EntityDescriptionList = new List<DuplicateEntityDescription>();

        public void Add(BaseEntity e)
        {
            DuplicateEntityDescription existingEntityDescription = _EntityDescriptionList.FirstOrDefault(ed => ed.SomeEntity.Equals(e));

            if (existingEntityDescription != null)
            {
                existingEntityDescription.Add(e);
            }
            else
            {
                DuplicateEntityDescription ed = new DuplicateEntityDescription(e, _EntityDescriptionList.Count.ToString());

                _EntityDescriptionList.Add(ed);
            }
        }

        public IEnumerator<DuplicateEntityDescription> GetEnumerator()
        {
            return ((IEnumerable<DuplicateEntityDescription>) _EntityDescriptionList).GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
